#include "AnimatedSprite.hpp"

#include "SpriteManager.hpp"

AnimatedSprite::AnimatedSprite()
    :m_time(),m_interval(0),m_lastUpdate(0),m_actualFrame(0)
{
    m_lastUpdate = m_time.GetElapsedTime();
}

AnimatedSprite::~AnimatedSprite()
{
}

void AnimatedSprite::addSprite(const std::string& spriteName)
{
    m_spriteList.push_back(spriteName);
}

const sf::Sprite& AnimatedSprite::getSprite(const SpriteManager& m_spriteManager, int angle, int level)
{
    return m_spriteManager.getSprite(m_spriteList[m_actualFrame],angle,level);
}

void AnimatedSprite::update()
{
    float time = m_time.GetElapsedTime();
    if ( time - m_lastUpdate > m_interval )
    {
        m_actualFrame++;
        m_lastUpdate = m_time.GetElapsedTime();

        if ( m_actualFrame >= m_spriteList.size() )
        {
            m_actualFrame = 0;
        }
    }
}
